package dao

import (
	"encoding/json"
	"fmt"
	"git.supremind.info/product/box/vehicle/internal/util"
)

type UpgradeLog struct {
	ID             uint      `gorm:"primary_key;auto_increment;not null" json:"id"`
	Version        string    `gorm:"version" json:"version"`
	Result         int       `gorm:"result" json:"result"`
	UpgradeModules string    `gorm:"upgrade_modules" json:"upgradeModules"`
	DebId          int       `gorm:"deb_id" json:"debId"`
	CreateTime     util.Time `gorm:"create_time" json:"createTime"`
	UpdateTime     util.Time `gorm:"update_time" json:"updateTime"`
}

func init() {
	fmt.Println("------------------ UpgradeLog init ------------------")
}

func (t *UpgradeLog) TableName() string {
	return "upgrade_log"
}

func GetUpgradeLogList() (list []UpgradeLog) {
	DB.Debug().Model(&UpgradeLog{}).Order("create_time desc").Find(&list)
	return list
}

func (t *UpgradeLog) ToJsonStr() string {
	marshal, err := json.Marshal(t)
	if err != nil {
		return ""
	}
	return string(marshal)
}
